
<body>
    <div class="panel admin-panel">
        <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
        <div class="body-content">
            <div class="form-x">  
                <div class="form-group">
                    <div class="label">
                        <label>软件名：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w50" data-validate="required:请输入软件名" value="千变计划时时彩软件" id="name" />
                        <div class="tips"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>封面：</label>
                    </div>
                    <div class="field">
                        <input type="hidden" id="thumb"/>
                        <input type="text" id="thumb_front" name="img" class="input tips" style="width:25%; float:left;"  value=""  data-toggle="hover" data-place="right" data-image="" />
                        <input type="file" style="float:left;" id="uploadthumb" name="file">
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>软件压缩包：</label>
                    </div>
                    <div class="field">
                        <input type="hidden" id="download"/>
                        <input type="file" style="float:left;" id="uploadsoftware" name="software">
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>类别：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w50" data-validate="required:请输入软件名"  value="彩票软件" id="cate" />
                        <div class="tips"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>适用：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w50"  data-validate="required:请输入软件名"  value="所有彩种" id="lottery" />
                        <div class="tips"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>操作系统：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w50"  name="title" data-validate="required:请输入软件名" value="win9x/XP/win7/Vista" id="os" />

                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>使用说明：</label>
                    </div>
                    <div class="field">
                        <script id="editor" type="text/plain" style="width:800px;height:500px;"></script>
                    </div>
                </div>
                <div class="clear"></div>
                <div class="form-group">
                    <div class="label">
                        <label>评分：</label>
                    </div>
                    <div class="field">
                        <input type="text" class="input w50"  value="100" data-validate="member:只能为数字" id="score" />
                        <div class="tips">0-100</div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label></label>
                    </div>
                    <div class="field">
                        <button class="button bg-main icon-check-square-o" type="button" id="submitBtn"> 提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body></html>
<script>
    $(function () {
        $("#uploadthumb").change(function () {
            if (confirm("您确定上传这张图片吗?")) {
                //获取文件上传对象 
                var objfile = $(this).get(0).files[0];
                //创建文件路径 
                src = window.URL.createObjectURL(objfile);
                $("#thumb_front").attr("data-image", src);
                var formdata = new FormData(); //创建表单数据对象
                formdata.append("file", objfile); //将文件添加入表单对象,下标为aa
                $.ajax({
                    "url": "<?= site_url('upload/do_upload') ?>",
                    "type": "POST",
                    "data": formdata,
                    "dataType": "json",
                    "processData": false,
                    "contentType": false,
                    "success": function (redata) {
                        let server_thumb_url = redata.uploadInfo.upload_data.file_name;
                        $("#thumb").val(server_thumb_url);
                        alert(redata.error);
                    }
                })
            }
        });

        $("#uploadsoftware").change(function () {
            if (confirm("您确定上传这个软件么?")) {
                var objfile = $(this).get(0).files[0];
                var formdata = new FormData(); //创建表单数据对象
                formdata.append("software", objfile); //将文件添加入表单对象
                $.ajax({
                    "url": "<?= site_url('upload/upload_software') ?>",
                    "type": "POST",
                    "data": formdata,
                    "dataType": "json",
                    "processData": false,
                    "contentType": false,
                    "success": function (redata) {
                        let server_software_url = redata.uploadInfo.upload_data.file_name;
                        $("#download").val(server_software_url);
                        alert(redata.error);
                    }
                })
            }
        });


    });
    $('#submitBtn').click(function () {
        let name = $("#name").val();
        let score = $("#score").val();
        let cate = $("#cate").val();
        let lottery = $("#lottery").val();
        let os = $("#os").val();
        let download = $("#download").val();
        let help = ue.getContent();
        let thumb = $("#thumb").val();

        let url = "<?= site_url('software/adding') ?>";
        let jsonData = {
            'name': name,
            'score': score,
            'cate': cate,
            'lottery': lottery,
            'os': os,
            'download': download,
            'help': help,
            'thumb': thumb
        };
        console.log(jsonData);
        $.post(url, jsonData, function (redata) {
            alert(redata.error);
        }, 'json');
    })



</script>
<script type="text/javascript" charset="utf-8" src="<?= base_url() ?>static/backend/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="<?= base_url() ?>static/backend/ueditor/ueditor.all.min.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="<?= base_url() ?>static/backend/ueditor/lang/zh-cn/zh-cn.js"></script>


<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');
    function isFocus(e) {
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e) {
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }
    function getAllHtml() {
        alert(UE.getEditor('editor').getAllHtml())
    }
    function getContent() {
        var arr = [];
        arr.push("使用editor.getContent()方法可以获得编辑器的内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getContent());
        alert(arr.join("\n"));
    }
    function getPlainTxt() {
        var arr = [];
        arr.push("使用editor.getPlainTxt()方法可以获得编辑器的带格式的纯文本内容");
        arr.push("内容为：");
        arr.push(UE.getEditor('editor').getPlainTxt());
        alert(arr.join('\n'))
    }
    function setContent(isAppendTo) {
        var arr = [];
        arr.push("使用editor.setContent('欢迎使用ueditor')方法可以设置编辑器的内容");
        UE.getEditor('editor').setContent('欢迎使用ueditor', isAppendTo);
        alert(arr.join("\n"));
    }
    function setDisabled() {
        UE.getEditor('editor').setDisabled('fullscreen');
        disableBtn("enable");
    }

    function setEnabled() {
        UE.getEditor('editor').setEnabled();
        enableBtn();
    }

    function getText() {
        //当你点击按钮时编辑区域已经失去了焦点，如果直接用getText将不会得到内容，所以要在选回来，然后取得内容
        var range = UE.getEditor('editor').selection.getRange();
        range.select();
        var txt = UE.getEditor('editor').selection.getText();
        alert(txt)
    }

    function getContentTxt() {
        var arr = [];
        arr.push("使用editor.getContentTxt()方法可以获得编辑器的纯文本内容");
        arr.push("编辑器的纯文本内容为：");
        arr.push(UE.getEditor('editor').getContentTxt());
        alert(arr.join("\n"));
    }
    function hasContent() {
        var arr = [];
        arr.push("使用editor.hasContents()方法判断编辑器里是否有内容");
        arr.push("判断结果为：");
        arr.push(UE.getEditor('editor').hasContents());
        alert(arr.join("\n"));
    }
    function setFocus() {
        UE.getEditor('editor').focus();
    }
    function deleteEditor() {
        disableBtn();
        UE.getEditor('editor').destroy();
    }
    function disableBtn(str) {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++]; ) {
            if (btn.id == str) {
                UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
            } else {
                btn.setAttribute("disabled", "true");
            }
        }
    }
    function enableBtn() {
        var div = document.getElementById('btns');
        var btns = UE.dom.domUtils.getElementsByTagName(div, "button");
        for (var i = 0, btn; btn = btns[i++]; ) {
            UE.dom.domUtils.removeAttributes(btn, ["disabled"]);
        }
    }

    function getLocalData() {
        alert(UE.getEditor('editor').execCommand("getlocaldata"));
    }

    function clearLocalData() {
        UE.getEditor('editor').execCommand("clearlocaldata");
        alert("已清空草稿箱")
    }
</script>